package com.zjhs.media.service.impl;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zjhs.cooperatives.web.service.I${ClassName}Service;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zjhs.cooperatives.web.mapper.${ClassName}Mapper;
import com.zjhs.cooperatives.web.domain.${ClassName};
import com.zjhs.cooperatives.web.service.I${ClassName}Service;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.transaction.annotation.Transactional;
import com.zjhs.common.exception.ServiceException;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * ${table.comment}Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-11-09
 */
@Slf4j
@Service
public class ${ClassName}ServiceImpl extends ServiceImpl<${ClassName}Mapper, ${ClassName}> implements I${ClassName}Service
{
    @Resource
    private ${ClassName}Mapper ${className}Mapper;

    @Autowired
    private I${ClassName}Service ${className}Service;




    @Override
    public ${ClassName} select${ClassName}ById(Long id)
    {
        return ${className}Mapper.selectById(id);
    }

    @Override
    public List<${ClassName}> select${ClassName}List(${ClassName} ${className})
    {
        QueryWrapper<${ClassName}> queryWrapper = new QueryWrapper<${ClassName}>();
        if (${className}!=null){
            //根据条件查询
//            queryWrapper.eq(StringUtils.isNotEmpty(${className}.getPersonName()),"person_name",${className}.getPersonName());
//            queryWrapper.eq(StringUtils.isNotEmpty(${className}.getPersonType()),"person_type",${className}.getPersonName());
//            queryWrapper.eq(StringUtils.isNotEmpty(${className}.getSpeciality()),"speciality",${className}.getPersonName());
//            queryWrapper.lt(${className}.getStartTime()!=null,"create_time",${className}.getEndTime());
//            queryWrapper.ge(${className}.getEndTime()!=null,"create_time",${className}.getStartTime());


        }
        return ${className}Mapper.selectList(queryWrapper);
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public int insert${ClassName}(${ClassName} ${className})
    {
        return ${className}Mapper.insert(${className});
    }


    @Transactional(rollbackFor = Exception.class)
    @Override
    public int update${ClassName}(${ClassName} ${className})
    {
        if (${className}.getId()==null){
            throw new ServiceException("id不能为空");
        }
        return ${className}Mapper.updateById(${className});
    }


    @Override
    public int delete${ClassName}ByIds(Long[] ids)
    {
        return ${className}Mapper.deleteBatchIds(Arrays.asList(ids));
    }


    @Override
    public int delete${ClassName}ById(Long id)
    {
        return ${className}Mapper.deleteById(id);
    }

}
